#!/bin/sh

#-------------------------------------#
#  SGT (Software Generation Toolkit)  #
#-------------------------------------#
#                                     #
#        Show all available           #
#          script for SGT             #
#                                     #
#  GDE 17/03/2004 v2.1                #
#       Fix OS detection              #
#                                     #
#  GDE 02/03/2004 v2.0                #
#       Display all available         #
#       compiler keyword              #
#                                     #
#  GDE 17/12/2003 v1.8                #
#       Display last SGT release      #
#                                     #
#  GDE 03/07/2003 v1.7                #
#       check \MAK subdirectory       #
#                                     #
#  GDE 28/02/2003 v1.6                #
#       update for SGT 1.2.1          #
#                                     #
#  GDE 17/10/2002 v1.5                #
#       update for SGT 1.1.5          #
#                                     #
#  GDE 25/09/2002 v1.4                #
#       update for SGT 1.1.4          #
#                                     #
#  GDE 06/06/2002 v1.3                #
#       modify script name from       #
#       index_sgt to help_sgt         #
#                                     #
#  GDE 14/05/2002 v1.2                #
#       update for SGT 1.1.1          #
#       add create_pp script          #
#                                     #
#  GDE 07/05/2002 v1.1                #
#       update for SGT 1.1.0          #
#                                     #
#  GDE 10/04/2002 v1.0                #
#       creation                      #
#                                     #
#-------------------------------------#
# $1: variable / options              #
#-------------------------------------#



#-------------------------------------#
# Script informations
#-------------------------------------#
export SCRIPT_SGT_VER=2.1
export SCRIPT_SGT_DATE=17/03/2004
export SCRIPT_SGT_USER=GDE
export SCRIPT_SGT_NAME=help_sgt
export SCRIPT_SGT_USAGE="List of available scripts for SGT $SGT_VER"
#-------------------------------------#



#---------------------
# Check the validity of current directory
#---------------------
if [ ! -d mak ]
then
	export MSG_ERROR_SCRIPT=0
	export CMD_SCRIPT=Error
fi
#---------------------



#-------------------------------------#
# Parameters section
#-------------------------------------#
#---------------------
# Parameter 1 -> variable / options
#---------------------
if [ ! -z $1 ]
then
	if [ $1 = -v ]
	then
		export CMD_SCRIPT=Version
	else
		if [ $1 = -h ]
		then
			export CMD_SCRIPT=Help
		else
			if [ $1 = --help ]
			then
				export CMD_SCRIPT=Help
			else
				if [ $1 = -hm ]
				then
					export CMD_SCRIPT=More
				else
					if [ $1 = -u ]
					then
						export CMD_SCRIPT=Usage
					else
						if [ $1 = -c ]
						then
							export CMD_SCRIPT=Compiler
						else
							export MSG_ERROR_SCRIPT=1
							export CMD_SCRIPT=Error
						fi
					fi
				fi
			fi
		fi
	fi
fi



#-------------------------------------#
# Process section
#-------------------------------------#
#---------------------
# Display the list of SGT scripts available
#---------------------
if [ -z $1 ] && [ -z $CMD_SCRIPT ]
then
	#---------------------
	# Display SGT infos
	#---------------------
		
	if [ $TERM = cygwin ]
	then
		if [ -f /cygdrive/u/projet/tools/share/Tatoo/sgt/info.sh ]
		then
			/cygdrive/u/projet/tools/share/Tatoo/sgt/info.sh
		fi
	else
		if [ -f /projet/tools/share/Tatoo/sgt/info.sh ]
		then
			/projet/tools/share/Tatoo/sgt/info.sh
		fi
	fi

	echo " "
	echo "------------------------------------"
	echo "    $SCRIPT_SGT_USAGE"
	echo "------------------------------------"
	echo "Main SGT scripts :"
	make_lib -u
	compile -u
	link_obj -u
	create_bin -u
	echo "------------------------------------"
	echo "GENE2P scripts :"
	create_pp -u
	create_e2p -u
	echo "------------------------------------"
	echo "TOOLS scripts :"
	compile_sce -u
	build_csn -u
	make_rte -u
	create_tmt -u
	echo "------------------------------------"
	echo "Other scripts :"
	make_delivery -u
	get_pvcs -u
	setlower -u
	zip_src -u
	disp -u
	find_err -u
	find_file -u
	old_sgt -u
	echo "------------------------------------"
	exit
fi


#---------------------
# Display the list of all keyword used by SGT in gen.mak
#---------------------
if [ ! -z $1 ] && [ $CMD_SCRIPT = Compiler ]
then
	echo " "
	echo "------------------------------------"
	echo "  Compiler keyword (set in gen.mak)"
	echo "------------------------------------"
	echo " "
	echo "     Old compilers"
	echo "------------------------------------"
	echo " oneca       : JS3.3     compiler"
	echo " oneca_35    : JS3.51    compiler"
	echo " onecat35    : JS3.51    compiler -> mode thumb"
	echo " "
	echo "    Specifics keywords"
	echo "------------------------------------"
	echo " d1ct        : ADS 1.12  compiler for downloader (dwl.bin)"
	echo " d1ct12      : ADS 1.12  compiler for downloader (dwl.bin / thumb)"
	echo " gcc         : gcc for PC"
	echo " gcc_arm     : gcc for ARM"
	echo " "
	echo "     ADS 1.12 compiler build 837"
	echo "------------------------------------"
	echo " oneca_12    : ADS 1.12  compiler (build 837)"
	echo " onecat12    : ADS 1.12  compiler (build 837)       ->  mode thumb)"
	echo " swift_12    : ADS 1.12  compiler for chipset SWIFT"
	echo " swift_t12   : ADS 1.12  compiler for chipset SWIFT ->  mode thumb)"
	echo " what        : ADS 1.12  compiler for chipset WHAT  ->  mode thumb)"
	echo " dune        : ADS 1.12  compiler for chipset DUNE  (UMTS)"
	echo " "
	echo "     ADS 1.12 compiler build 848"
	echo "------------------------------------"
	echo " ads12_b848  : ADS 1.12  compiler (build 848)"
	echo " ads12t_b848 : ADS 1.12  compiler (build 848 / mode thumb)"
	echo " "
	echo "     RVCT 2.X compiler"
	echo "------------------------------------"
	echo " rvct20  : ARM/Thumb C/C++ Compiler, RVCT2.0.1 [Build 277]"
	echo " rvct21  : ARM/Thumb C/C++ Compiler, RVCT2.1"
	echo " "
	echo " "
	exit
fi



#-------------------------------------#
# Help script section
#-------------------------------------#
if [ -z $CMD_SCRIPT ]
then
	export CMD_SCRIPT=Version
fi

#---------------------
# Usage
#---------------------
if [ $CMD_SCRIPT = Usage ]
then
	echo "  $SCRIPT_SGT_NAME	$SCRIPT_SGT_USAGE"
	exit
fi

#---------------------
# Version
#---------------------
echo " "
echo "-------------------------------------"
echo " '$SCRIPT_SGT_NAME' (release "$SCRIPT_SGT_VER") for SGT "$SGT_VER". Last update by "$SCRIPT_SGT_USER" on "$SCRIPT_SGT_DATE
echo "  $SCRIPT_SGT_USAGE"
if [ $CMD_SCRIPT = Version ]
then
	exit
fi

#---------------------
# Simple help
#---------------------
if [ $CMD_SCRIPT = Help ]
then
	echo "-------------------------------------"
	echo " $SCRIPT_SGT_NAME [-OPTION]"
	echo " "
	echo " -c  : Display all available compiler keyword"
	echo " "
	echo " "
	echo "  -h | --help  Display this help "
	echo "  -hm          Display more help about SGT" $SGT_VER
	echo "  -v           Display the version of the current script"
fi

#---------------------
# More help
#---------------------
if [ $CMD_SCRIPT = More ]
then
	#---------------------
	# Create and go to output directory
	#---------------------
	mkdir -p -m775 out
	cd out
	#---------------------
	make -f ../mak/gen.mak help USE_TARGET_FILE=OFF
fi



#-------------------------------------#
# Error messages section
#-------------------------------------#
if [ $CMD_SCRIPT = Error ]
then
	if [ $MSG_ERROR_SCRIPT = 0 ]
	then
		echo "-------------------------------------"
		echo " "
		echo "ERROR : The root path is not a valid SGT directory. Please check for the \MAK sub-directory"
	fi
	if [ $MSG_ERROR_SCRIPT = 1 ]
	then
		echo "-------------------------------------"
		echo " "
		echo  "ERROR : $1 option unknown !"
	fi
	echo " "
	echo " Check your command line or see help section -> $SCRIPT_SGT_NAME -h"
fi
